Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

285
Vistas
Sending data to and receiving data from localhost in Unity caused "IOException: Too many open files" error

To test the networking part of my Unity application, I have an "imitatee" game object that moves according to the keyboard input. The networking manager component (1) gets the movement data of the "imitatee" and sends it to a node.js localhost server using PUT and also (2) gets back the from localhost and applies it to the "imitator" object. The program worked fine, but after a while I got the error:

IOException: Too many open files

A window also popped up in the Unity editor saying that "Opening files failed" and then the editor crashed. I think that it was caused by memory not being disposed properly but have not figured out exactly how. Here is the GameManager code:

NetworkingManager.cs

public class Data
{
    public float posX;
    ...

    public Data(float posX...)
    {
        this.posX = posX;
        ...
    }
}

public class NetworkingManager : MonoBehaviour
{

    private GameObject imitator;
    private GameObject imitatee;

    private Data data;
    private string jsonData;
    private Data receivedData;

    private string uri = "http://localhost:3000/";

    private void Awake()
    {
        // Assign references
        ...
    }

    private IEnumerator SendData()
    {
        data = new Data(
            imitatee.transform.position.x,
            ...
            );

        jsonData = JsonUtility.ToJson(data);

        using (UnityWebRequest req = UnityWebRequest.Put(uri, jsonData))
        {
            req.SetRequestHeader("Content-Type", "application/json");
            yield return req.SendWebRequest();
    

            if (req.isNetworkError || req.isHttpError)
            {
                Debug.Log(req.error);
            }
        }

    }

    private IEnumerator ReceiveData()
    {

        using (UnityWebRequest req = UnityWebRequest.Get(uri))
        {
            yield return req.SendWebRequest();

            if (req.isNetworkError)
            {
                Debug.Log(req.error);
            }
            else
            {
                receivedData = JsonUtility.FromJson<Data>(req.downloadHandler.text);

                imitator.transform.position = new Vector3(
                    receivedData.posX,
                    ...
                    );

                ...
            }
        }
        
    }

    void Update()
    {
        StartCoroutine(SendData());
        StartCoroutine(ReceiveData());
    }
}

Besides, there was no error logged for the node.js backend.

backend.js

const express = require('express')
const app = express()
app.use(express.json())
const port = 3000
var data

app.get('/', (req, res) => {
  if (data) res.json(data)
})

app.put('/', (req, res) => {
  data = req.body
  console.log("Received " + req.body) 
})

app.listen(port, () => {
  console.log(`App listening at http://localhost:${port}`)
})

Appreciate your help!

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda